package com.example.note.mapper;

import com.example.note.model.NoteInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 */
@Mapper
public interface NoteInfoMapper {
    /**
     * 获取笔记列表
     */
    @Select("select * from note where delete_flag = 0 order by create_time desc")
    List<NoteInfo> queryNoteList();

    /**
     * 根据笔记Id,获取笔记详情
     */
    @Select("select * from note where id=#{id} and delete_flag = 0")
    NoteInfo queryById(Integer id);

    /**
     * 编辑笔记
     */
    @Select("update note set title =#{title},content=#{content} where id=#{id}")
    Integer updateNote(NoteInfo noteInfo);

    /**
     * 根据ID，删除笔记
     */
    @Update("update note set delete_flag = 1 where id =#{id}")
    Integer deleteNote(Integer id);

    /**
     * 添加笔记
     */
    @Insert("insert into note(title,content,user_id) values(#{title},#{content},#{userId})")
    Integer insertNote(NoteInfo noteInfo);
}

